﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ManagerCategory.aspx.cs"
    Inherits="ShowroomMobile.ManagerCategory" MasterPageFile="~/AdminSite.Master"
    Title="Category Management" ValidateRequest="false" Theme="tbmobile" %>

<%@ Register Assembly="ShowroomMobile" Namespace="jNET.Controls" TagPrefix="cc" %>
<%@ Register Src="~/Controls/DataPagerCtrl.ascx" TagName="DataPager" TagPrefix="uc" %>
<asp:Content runat="server" ID="cManagerCategory" ContentPlaceHolderID="body">
    <link rel="stylesheet" type="text/css" href="css/treeview.css" />
    <asp:UpdatePanel runat="server" ID="upCategroy">
        <ContentTemplate>
            <style>
                #ifrm
                {
                    width: 100%;
                    height: 440px;
                    border: 0px;
                }
            </style>
            <script type="text/javascript">
                function ShowCategoryForm() {
                    document.getElementById("formCategory").style.display = "block";
                }
                function CheckIsChild(ckb) {
                    var hidIsChild = document.getElementById("<%= hidIsChild.ClientID %>");
                    hidIsChild.value = ckb.checked;
                }
                function HideCategoryForm() {
                    $("#formCategory").hide();
                }
                function ClearValueCategoryForm() {
                    $("#formCategory input[type=text]").val("");
                    $("#formCategory input[type=checkbox]").val("");
                    $("#formCategory input[type=checkbox]").css("display", "block");
                    var hidCategoryName = document.getElementById('<%= hidCategoryName.ClientID %>');
                    if (hidCategoryName.value == "") {
                        $("#ckbIsChild").css("display", "none");
                        $("#lblIsChild").css("display", "none");
                    }
                }
                function InputValueCategoryForm() {
                    var hidCategoryName = document.getElementById('<%= hidCategoryName.ClientID %>');
                    if (hidCategoryName.value == "") {
                        showNotification('Star Case', 'Select a category to edit', 8000); return;
                    }

                    var txtCategoryName = document.getElementById('<%= txtCategoryName.ClientID %>');
                    txtCategoryName.value = hidCategoryName.value;
                    $("#ckbIsChild").css("display", "none");
                    $("#lblIsChild").css("display", "none");
                    ShowCategoryForm();
                }
                function MaskHandle(handle) {
                    var hidHandle = document.getElementById('<%= hidHandle.ClientID %>');
                    hidHandle.value = handle;
                }
                function ConfirmDelete() {
                    var hidCategoryName = document.getElementById('<%= hidCategoryName.ClientID %>');
                    if (hidCategoryName.value == "") {
                        showNotification('Star Case', 'Select a category to delete', 8000); return false;
                    }
                    return confirm('Are you sure to delete the selected item?');
                }
                function AddProduct() {
                    var hidCategoryName = document.getElementById('<%= hidCategoryName.ClientID %>');
                    if (hidCategoryName.value == "") {
                        showNotification('Star Case', 'Select a category to add product', 8000); return false;
                    }
                    var hidUrlAddProduct = document.getElementById('<%= hidUrlAddProduct.ClientID %>');
                    var d = $('#jqwin').html('<iframe id="ifrm" src="' + hidUrlAddProduct.value + '"></iframe>');
                    d.dialog({ width: 750, height: 500, title: 'Add Product', modal: true,
                        close: function (event, ui) {
                            var btnReloadGridCurrentProducts = document.getElementById("<%= btnReloadGridCurrentProducts.ClientID %>");
                            btnReloadGridCurrentProducts.click();
                        }
                    });
                    return true;
                }
                function SelectAll() {
                    if ($("#ckbSelectAll").is(':checked')) {
                        $(".ckbSelect").attr("checked", true);
                        $(".ckbSelect").each(function () {
                            Select(this);
                        });
                    }
                    else {
                        $(".ckbSelect").removeAttr("checked");
                    }
                }
                function Select(ckb) {
                    var hidSelectedProductID = document.getElementById("<%= hidSelectedProductID.ClientID %>");
                    if (ckb.checked) {
                        hidSelectedProductID.value += "," + $(ckb).attr("value") + ",";
                    }
                    else {
                        hidSelectedProductID.value = hidSelectedProductID.value.replace("," + $(ckb).attr("value") + ",", "");
                    }
                }
            </script>
            <div id="jqwin">
            </div>
            <div style="float: left; width: 200px; border: solid 1px #000; position: relative;">
                <div class="titleAdmin">
                    <asp:ImageButton runat="server" ID="btnAdd" ImageUrl="~/images/add.png" ToolTip="Add Category"
                        OnClientClick="ShowCategoryForm(); ClearValueCategoryForm(); MaskHandle('add'); return false;" />
                    &nbsp;&nbsp;<asp:ImageButton runat="server" ID="btnEdit" ImageUrl="~/images/edit.png"
                        ToolTip="Edit Category" OnClientClick="InputValueCategoryForm(); MaskHandle('edit'); return false;" />&nbsp;&nbsp;<asp:ImageButton
                            runat="server" ID="btnRemove" ImageUrl="~/images/delete.png" OnClientClick="return ConfirmDelete();"
                            ToolTip="Remove Category" OnClick="btnRemove_Click" /></div>
                <asp:TreeView ID="trvCategory" runat="server" CssClass="treeview" NodeStyle-CssClass="node"
                    SelectedNodeStyle-CssClass="nSelected" HoverNodeStyle-CssClass="nHover" NodeStyle-ImageUrl="~/images/category_icon.png"
                    NodeStyle-NodeSpacing="3" OnTreeNodePopulate="trvCategory_TreeNodePopulate" OnSelectedNodeChanged="trvCategory_SelectedNodeChanged">
                    <%--<Nodes>
                        <asp:TreeNode Text="Product">
                            <asp:TreeNode Text="Product 1" />
                            <asp:TreeNode Text="Product 2" />
                            <asp:TreeNode Text="Product 3" />
                        </asp:TreeNode>
                        <asp:TreeNode Text="Exclusive Collection" />
                        <asp:TreeNode Text="New Arrival" />
                        <asp:TreeNode Text="Reseller" />
                    </Nodes>--%>
                </asp:TreeView>
            </div>
            <div style="float: left; width: 570px; margin-left: 5px; border: solid 1px #000;">
                <div class="titleAdmin">
                    <a onclick="AddProduct()" style='cursor:pointer'>
                        <img src="~/images/add.png" runat="server" />Add Existing Products </a>
                    &nbsp;
                    <asp:HyperLink NavigateUrl="~/UpdateProduct.aspx" id='lnkNewProduct' runat="server" style='cursor:pointer'>
                        <img id="Img1" src="~/images/add.png" runat="server" />Add New Product </asp:HyperLink>
                </div>
                <div id="formCategory" align="center" style="display: none; padding-top: 5px; padding-bottom: 5px;">
                    <table cellpadding="5" cellspacing="0">
                        <tr>
                            <td>
                                Category Name
                                <asp:TextBox runat="server" ID="txtCategoryName" ValidationGroup="saveCategory" Width="200px" />
                            </td>
                            <td>
                                <input id="ckbIsChild" type="checkbox" onchange="CheckIsChild(this);" />
                            </td>
                            <td>
                                <span id="lblIsChild">As Sub Category</span>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="10" align="center">
                                <asp:Button runat="server" ID="btnSaveCategory" ValidationGroup="saveCategory" Text="Submit"
                                    OnClick="btnSaveCategory_Click" />&nbsp;<asp:Button runat="server" ID="btnCancel"
                                        Text="Cancel" OnClientClick="HideCategoryForm();" />
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage=""
                                    ValidationGroup="saveCategory" ControlToValidate="txtCategoryName"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                    </table>
                </div>
                <cc:CustomGrid Width="100%" AllowRowSelect="false" GridLines="None" CssClass="clientGrid"
                    ID="gridCurrentProducts" runat="server" AutoGenerateColumns="false" DataKeyField="ID"
                    OnItemCommand="gridCurrentProducts_ItemCommand" PageSize="10" AllowPaging="true"
                    AllowCustomPaging="true" OnNeedDataSource="gridCurrentProducts_OnNeedDataSource"
                    OnPageIndexChanged="gridCurrentProducts_PageIndexChanged" PagerStyle-Mode="NumericPages">
                    <Columns>
                        <cc:CustomTemplateField UniqueName="ImageUrl" HeaderText="Image" ItemStyle-Width="120px"
                            ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <img src='<%# ShowroomMobile.Utilities.GetKeySetting("PathUploadImageThumb") + "/" + Eval("ImageUrl") %>'
                                    class="imgAdmin" />
                            </ItemTemplate>
                        </cc:CustomTemplateField>
                        <cc:CustomTemplateField HeaderText="Name" ItemStyle-Width="30%" HeaderStyle-Width="30%">
                            <ItemTemplate>
                                <a href='ProductDetails.aspx?cid=<%# Eval("CategoryID") %>&id=<%# Eval("ProductID") %>'>
                                    <%# Eval("Name").ToString() %></a>
                            </ItemTemplate>
                        </cc:CustomTemplateField>
                        <cc:CustomTemplateField HeaderText="Description" ItemStyle-Width="60%" HeaderStyle-Width="60%">
                            <ItemTemplate>
                                <%# ShowroomMobile.Utilities.GetSubString(Eval("Description").ToString(), 200)%>
                            </ItemTemplate>
                        </cc:CustomTemplateField>
                        <cc:CustomTemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-Width="10px" HeaderStyle-Width="10px" HeaderText="">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnDelete" runat="server" ToolTip="Delete" OnClientClick='return confirm("Are you sure to delete this item?");'
                                    CommandName="Delete" CommandArgument='<%# Eval("ID") %>'>
                                    <asp:Image ImageUrl="~/images/delete.png" runat="server" ID="imgDelete" />
                                </asp:LinkButton></ItemTemplate>
                            <HeaderTemplate>
                                <asp:LinkButton ID="btnDeleteAll" runat="server" ToolTip="Delete All" OnClientClick='return confirm("Are you sure to delete all item(s)?");'
                                    CommandName="DeleteAll">
                                    <asp:Image ImageUrl="~/images/delete.png" runat="server" ID="imgDeleteAll" />
                                </asp:LinkButton></HeaderTemplate>
                        </cc:CustomTemplateField>
                    </Columns>
                </cc:CustomGrid>
                <asp:HiddenField runat="server" ID="hidCategoryName" />
                <asp:HiddenField runat="server" ID="hidHandle" />
                <asp:HiddenField runat="server" ID="hidSelectedProductID" />
                <asp:HiddenField runat="server" ID="hidIsChild" Value="false" />
                <asp:HiddenField runat="server" ID="hidUrlAddProduct" />
                <asp:Button runat="server" ID="btnReloadGridCurrentProducts" Style="display: none"
                    OnClick="btnReloadGridCurrentProducts_Click" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
